#include "log.hpp"
#include "shm.hpp"
#include "namepipe.hpp"
extern Log log;
int main()
{
    namepipe namepipe;
    int shmid=CreateShareMem();
    char*shmaddr=(char*)shmat(shmid,nullptr,0);

    //打开管道，利用管道的互斥机制辅助共享内存通信
    int fd =open(path,O_RDONLY);
    if(fd<0)
    {
        log(Fatal, "open error, error string: %s, error code: %d", strerror(errno), errno);
        exit(-1);
    }
    //通信：读
    while(1)
    {
        //我们假装通过管道传递信息，实则是借用，真正的数据通过共享内存读取
       char c=0;
       ssize_t n=read(fd,&c,1);
       if(n<0) break;
       else if(n==0) break;
       //真正的数据
       cout<<shmaddr<<endl;
       sleep(1);
    }
    
    shmdt(shmaddr);
    shmctl(shmid, IPC_RMID, nullptr);
    close(fd);
    return 0;
}